"""
File: log_utils.py
Author: ershixiong
Date: 2023/11/21
describe:


# 判断日志文件夹是否存在
log_path = os.sep.join([Utils.get_root_dir(), 'logs'])
if not os.path.exists(log_path):
    os.mkdir(log_path)

file_handle = logging.FileHandler(filename=f'{log_path}/api_object.log', encoding='utf-8')
file_handle.setLevel(logging.DEBUG)


"""
import datetime
import logging
import os

from hogwarts.Calculator.utils.utils import get_root_path

# 创建logger实例
logger = logging.getLogger('auto test')
# 设置日志级别
logger.setLevel(logging.DEBUG)

# 添加流处理器
ch = logging.StreamHandler()
ch.setLevel(logging.DEBUG)

file_path = os.sep.join([get_root_path(), 'logs'])
if not os.path.exists(file_path):
    os.mkdir(file_path)

timestamps = int(datetime.datetime.now().timestamp())
# 添加文件处理器
file_handle = logging.FileHandler(filename=f'{file_path}/test_{timestamps}.log', encoding='utf-8')

# 设置日志打印格式
formatter = logging.Formatter('%(asctime)s %(name)s %(levelname)s %(message)s')
# 添加格式配置
ch.setFormatter(formatter)
file_handle.setFormatter(formatter)

# 添加流配置
logger.addHandler(ch)
logger.addHandler(file_handle)
